﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace TestApplication.business.src
{
    public class Spat : List<Point?>
    {
        private int sumX;
        private int sumY;
        private Color color;

        public Color Color
        {
            get { return color; }
            set { color = value; }
        }
        private Double tolerance;

        public Double Tolerance
        {
            get { return tolerance; }
            set { tolerance = value; }
        }
        private Point? firstPoint;

        public Point? FirstPoint
        {
            get { return firstPoint; }
            set { firstPoint = value; }
        }

        public Spat(Color color, Double tolerance) : base()
        {
            this.color = color;
            this.tolerance = tolerance;
            this.firstPoint = null;
            this.sumX = 0;
            this.sumY = 0;
        }

        public void myAdd(Point? p)
        {
            this.sumX += p.Value.X;
            this.sumY += p.Value.Y;
            this.Add(p);
        }

        public Point? getCenter()
        {
            if (this.Count != 0)
            {
                return new Point(Convert.ToInt32(Math.Round((float)sumX / this.Count)), Convert.ToInt32(Math.Round((float)sumY / this.Count)));
            }
            return null;
        }

        public void reset()
        {
            this.Clear();
            this.sumX = 0;
            this.sumY = 0;
        }
    }
}
